from page.base_page import BasePage
from appium.webdriver.common.appiumby import AppiumBy as By
class PlusPage(BasePage):
    """加号页面"""
    #定位器
    keep_a_diet_diary_locator=(By.XPATH,'//android.widget.LinearLayout[@resource-id="com.xiachufang:id/create_diet_btn"]/android.widget.ImageView')
    breakfast_locator=(By.XPATH,'//android.view.View[@content-desc="早餐"]')
    banana_locator=(By.XPATH,'//android.view.View[@index=5]')
    sure_locator=(By.XPATH,'//android.view.View[@content-desc="确定"]')
    add_to_list_locator=(By.XPATH,'//android.view.View[@bounds=[40,744][860,844]]')
    currently_add_text_locator=(By.ACCESSIBILITY_ID, "香蕉999.0根\n133366.5千卡\n删除")
    currently_add_locator=(By.ANDROID_UIAUTOMATOR,'new UiSelector().textContains("数量必须大于")')
    modify_value_locator=(By.XPATH,'//android.view.View[@content-desc="0.0"]')
    def click_keep_a_diet_diary(self):
        """点击记饮食"""
        self.show_waiting(self.driver, self.keep_a_diet_diary_locator).click()
    def click_breakfast(self):
        """点击早餐"""
        self.show_waiting(self.driver, self.breakfast_locator).click()
    def click_breakfast(self):
        """点击早餐"""
        self.show_waiting(self.driver, self.breakfast_locator).click()
    def click_banana(self):
        """点击香蕉"""
        self.show_waiting(self.driver, self.banana_locator).click()
    def click_sure(self):
        """点击确定"""
        self.show_waiting(self.driver, self.sure_locator).click()
    def click_add_to_list(self):
        """点击添加列表"""
    def currently_add_text(self):
        """提取目标元素的文本（从content-desc属性）"""
        # 等待元素出现并获取
        element =  self.show_waiting(self.driver, self.currently_add_text_locator)
        # 从content-desc属性提取文本
        full_text = element.get_attribute('content-desc')
        # 如果需要进一步提取“香蕉999”部分，可加正则处理（参考之前的方法）
        return full_text
    def currently_add(self):
        """提取添加失败的文本"""
        return self.show_waiting(self.driver, self.currently_add_locator).text
    def modify_value(self):
        """提取添加的文本"""
        xx = self.show_waiting(self.driver, self.modify_value_locator)
        yy=xx.get_attribute("content-desc")
        return yy
